package com.inspinia.base.common.model;

import java.io.Serializable;

/**
 * ajax返回的结果用,转换成json使用
 * 由于jquery中,server至少需要返回能够解析成jason的字符串,jquery才认为这是一个成功的请求.及时响应码是200,jquery依然会认为请求失败,抛出parseError.
 *
 * @author Administrator
 */
public class AjaxResult implements Serializable {
    /**
     * 操作结果是否成功
     */
    private boolean success;
    /**
     * 返回的消息内容
     */
    private String message;

    /**
     * 返回状态
     */
    private String status;
    /**
     * 错误码
     */
    private Integer errorCode;

    /**
     * 自定义数据
     */
    private Object data;

    public AjaxResult() {
    }

    public AjaxResult(boolean success) {
        this.success = success;
    }

    public AjaxResult(Object data) {
        this(true, data);

    }

    public AjaxResult(boolean success, Object data) {
        this.success = success;
        this.data = data;
    }

    public AjaxResult(boolean success, String message) {
        this.success = success;
        if (success) {
            //成功的时候,不会设置消息
            this.data = message;
        } else {
            this.message = message;
        }
    }

    public AjaxResult(boolean success, Integer errorCode, String message) {
        this.success = success;
        if (success) {
            //成功的时候,不会设置消息
            this.data = message;
        } else {
            this.errorCode = errorCode;
            this.message = message;
        }
    }

    public AjaxResult(boolean success, Integer errorCode, String message, Object data) {
        this.success = success;
        this.data = data;
        this.errorCode = errorCode;
        this.message = message;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Integer getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(Integer errorCode) {
        this.errorCode = errorCode;
    }
}
